package kit4j.util.concurrent;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.ThreadFactory;

public class HandlerThreadFactory implements ThreadFactory {
	
	private UncaughtExceptionHandler handler;
	
	public HandlerThreadFactory(UncaughtExceptionHandler handler) {
		this.handler = handler;
	}

	@Override
	public Thread newThread(Runnable r) {
		Thread t = new Thread(r);
		
		t.setUncaughtExceptionHandler(handler);
		
		return t;
	}

}
